package com.atguigu.gmall.order.config;

import com.atguigu.gmall.common.constant.MqConst;
import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.CustomExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.HashMap;

/**
 * @author mqx
 * @date 2020-10-24 11:22:57
 */
@Configuration
public class OrderCanelMqConfig {

    //  定义交换机
    @Bean
    public CustomExchange delayExchange(){
        //  声明一个map
        HashMap<String, Object> map = new HashMap<>();
        //  设置参数
        map.put("x-delayed-type","direct");

        return new CustomExchange(MqConst.EXCHANGE_DIRECT_ORDER_CANCEL,"x-delayed-message",true,false,map);
    }

    //  定义队列
    @Bean
    public Queue delayQueue(){
        return new Queue(MqConst.QUEUE_ORDER_CANCEL,true);
    }

    //  绑定
    @Bean
    public Binding bindingDelay(){
        //  返回数据
        return BindingBuilder.bind(delayQueue()).to(delayExchange()).with(MqConst.ROUTING_ORDER_CANCEL).noargs();
    }

}
